package com.tongji.showroom.view.titleWindows
{	
	import com.tongji.showroom.events.ChangePropertyEvent;
	import com.tongji.showroom.utils.PopUpAdmin;
	import com.tongji.showroom.view.titleWindows.SingleFurnitureTitleWindow;
	import com.tongji.showroom.view.twoD.Furniture;
	
	import flash.events.MouseEvent;
	
	import mx.events.FlexEvent;
	import mx.events.FlexMouseEvent;
	import mx.managers.PopUpManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenzhongyuan
	 * 2011-8-28
	 */
	
	public class SingleFurnitureTitleWindowMediator extends Mediator
	{
		[Inject]
		public var singleTw:SingleFurnitureTitleWindow;
				
		override public function onRegister():void
		{
			eventMap.mapListener(singleTw, FlexMouseEvent.MOUSE_DOWN_OUTSIDE, removeTitleHandler, FlexMouseEvent);
			eventMap.mapListener(singleTw.enlargeBtn, MouseEvent.CLICK, sendLargeHandler, MouseEvent);
			eventMap.mapListener(singleTw.shrinkBtn, MouseEvent.CLICK, sendShrinkHandler, MouseEvent);
			eventMap.mapListener(singleTw.deleteBtn, MouseEvent.CLICK, sendDeleteHandler, MouseEvent);
			eventMap.mapListener(singleTw.filterBtn, MouseEvent.CLICK, setFilterHandler, MouseEvent);
		} 
		
		private function setFilterHandler(event:MouseEvent):void
		{
			PopUpAdmin.popupCenterWindow("filterWin", singleTw.parent, mediatorMap, false);
		}
		
		private function sendLargeHandler(event:MouseEvent):void
		{
			dispatch(new ChangePropertyEvent(ChangePropertyEvent.ENLARGE_FURNITURE, singleTw.owner as Furniture));		
		}
		
		private function sendShrinkHandler(event:MouseEvent):void
		{
			dispatch(new ChangePropertyEvent(ChangePropertyEvent.SHRINK_FURNITURE, singleTw.owner as Furniture));
		}
		
		private function sendDeleteHandler(event:MouseEvent):void
		{
			PopUpManager.removePopUp(singleTw);
			dispatch(new ChangePropertyEvent(ChangePropertyEvent.DELETE_FURNITURE, singleTw.owner as Furniture));			
		}
		
		//移除titlewindow
		private function removeTitleHandler(event:FlexMouseEvent):void
		{
			PopUpManager.removePopUp(singleTw);
		}
	}
}


